using System;
using System.Collections.Generic;
using System.Text;

namespace SysCommon.Tools
{
    public static class CollectionHelper
    {
        public static List<T[]> SplitArray<T>(T[] etys, int eachLength)
        {
            List<T[]> result = new List<T[]>(etys.Length / eachLength + 1);
            if (etys.Length <= eachLength)
            {
                result.Add(etys);
                return result;
            }

            List<T> etyList = new List<T>(eachLength);

            foreach(T ety in etys)
            {
                if (etyList.Count == eachLength)
                {
                    result.Add(etyList.ToArray());
                    etyList.Clear();
                }

                etyList.Add(ety);
            }

            if (etyList.Count > 0)
                result.Add(etyList.ToArray());

            return result;
        }
    }
}
